//回收客户
$(function() {
	var screenwidth, screenheight, mytop, getPosLeft, getPosTop
	screenwidth = $(window).width();
	screenheight = $(window).height();
	//获取滚动条距顶部的偏移
	mytop = $(document).scrollTop();
	//计算弹出层的left
	getPosLeft = screenwidth / 2 - 260;
	//计算弹出层的top
	getPosTop = screenheight / 2 - 150;
	//css定位弹出层
	$("#deptTree").css({ "left": getPosLeft, "top": getPosTop });
	$("#deploy").css({ "left": getPosLeft, "top": getPosTop });
	$("#bathDeploy").css({ "left": getPosLeft, "top": getPosTop });
	//当浏览器窗口大小改变时
	$(window).resize(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
		$("#deploy").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
		$("#bathDeploy").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
	});
	//当拉动滚动条时，弹出层跟着移动
	$(window).scroll(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });	
		$("#deploy").css({ "left": getPosLeft, "top": getPosTop+ mytop  });	
		$("#bathDeploy").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
	}); 
	 //获取页面文档的高度
	 var docheight = $(document).height();
	//追加一个层，使背景变灰
	$("body").append("<div id='greyBackGround'></div>");
	$("body").append("<div id='deptTreeBackGround'></div>");
	$("#greyBackGround").css({ "opacity": "0.1", "height": docheight });
	$("#deptTreeBackGround").css({ "opacity": "0.1", "height": docheight });
	
	
	
	$("#deployBtn").click(function(){
		var tempThis=$(this);
		var deployDeptName = $("#tempDeptId")[0].value;
		var deployEmpName = $("#deployEmpNo option:selected").text();
		$("#deployDeptName")[0].value=deployDeptName;
		$("#deployEmpName")[0].value=deployEmpName;
		var reason = $("#reason")[0].value;
		if(reason==null || reason==""){
			alert("请填写原因!");
			return;
		}
		var deployDeptId = $("#deployDeptId")[0].value;
		if(deployDeptId==null || deployDeptId==""){
			alert("请选择部门!");
			return;
		}
		
		 $.ajax({
             type: "POST",
             dataType:"text",
             url:getContextPathTemp()+"/ruleSet/customDeploy/checkIsCanDeploy",
             data:"deployDeptId="+deployDeptId,
             async: false,
             success: function(data){
            	 if(data=="true"){
            		 //$("#deployForm").submit();
            			var url = getContextPathTemp()+"/ruleSet/customDeploy/customDeploy";
            			 $.ajax({
            		         type: "POST",
            		         dataType:"json",
            		         url:url,
            		         data:$("#deployForm").serialize(),
            		         success: function(data){
            		        	 if(data=="1"){
            		        		 alert("调配成功!");
            		        		 var cusId=$("#cusId").val();
            		        		 $("#"+cusId+"stateLabel").attr("href","#");
            		        		 $("#"+cusId+"stateLabel").html("审核中");
            		        		 $("#deploy").fadeOut(100);
            		        		 $("#greyBackGround").css("display","none");
            		        		 return;
            		        	 }else if(data=="0"){
            		        		 alert("已经有其他人调配此记录!"); 
            		        		 return;
            		        	 }else if(data=="4"){
               		        		 alert("用户【"+deployEmpName+"】不能接收人工调配,请重新选择!"); 
               		        		return;
               		        	 }
               		        	 else if(data=="3"){
              		        		 alert("调配异常!"); 
              		        		return;
              		        	 }
//            		        	 $("#redirectForm").submit(); 
            		         }
            		     }); 
            		 
            	 }else{
            		alert("此部门已没有该用户使用的产品，请选择其他部门!"); 
            	 }
             }
         });
	});
	
	$("#deployBtnCancel").click(function(){
		 $("#greyBackGround").css("display","none");
		 $("#deploy").css("display","none");
		 $("#cusId")[0].value="";
		 $("#deployCName")[0].value="";
		 $("#deployMail")[0].value="";
		 $("#deployPhone")[0].value="";
		 $("#deployCurrentDeptNo")[0].value="";
		 $("#deployCurrentEmpNo")[0].value="";
		 $("#deployCurrentDeptName")[0].value="";
		 $("#deployCurrentEmpName")[0].value="";
		 $("#deployDeptName")[0].value="";
		 $("#deployEmpName")[0].value="";
		 
		 $("#productId")[0].value="";
		 $("#productCode")[0].value="";
		 $("#deployCurrentDeptNameLabel").html();
		 $("#deployCurrentEmpNameLabel").html();
		 
		 $("#reason")[0].value="";
		 $("#deployEmpNo").empty();
		 $("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
		 $("#deployDeptId")[0].value="";
		 $("#tempDeptId")[0].value="";
		 
	});
	
	$("#bathDeployBtn").click(function(){
		 $("#greyBackGround").css("display","none");
		 $("#bathDeploy").css("display","none");
		
	});
	$("#bathDeployBtnCancel").click(function(){
		 $("#greyBackGround").css("display","none");
		 $("#bathDeploy").css("display","none");
		
		
		
	});
	
	
	$("#deployDeptId").change(function(){
		var deptId =  $("#deployDeptId").val(); 
		var deployCurrentEmpNo =  $("#deployCurrentEmpNo").val();
		//alert("deployCurrentEmpNo:"+deployCurrentEmpNo);
		 $.ajax({
             type: "POST",
             url:getContextPathTemp()+"/ruleSet/customDeploy/getEmpByDeptId",
             data:"deptId="+deptId+"&currentEmpId="+deployCurrentEmpNo,
             async: false,
             error: function(request){
                 alert("Connection error");
                 location.reload();
             },
             success: function(data){
             	$("#deployEmpNo").empty();
            	$("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
            	 if(data!=""){
                 	var empList = eval(data);
                	if(empList!=""){
                    	for( var int = 0; int < empList.length; int++){
                    		var emp = empList[int];
                    		var empno = emp.empno;
                    		var ename = emp.ename;
                    		$("#deployEmpNo").append("<option value='"+empno+"'>"+ename+"</option>");
        				}
                	}
            	 }
             }
         }); 
	});
	
	$("#queryBtn").click(function(){
		//var tempDeptId = $("#queryTempDeptId")[0].value;
		//$("#queryDeptId")[0].value=tempDeptId;
		$("#queryForm").submit();
	});
	
	
	
	
	$("#bathDeployBtn").click(function(){
		//var deployDeptName = $("#deployDeptId option:selected").text();
		var deployDeptName = $("#tempDeptId")[0].value;
		//alert("deployDeptName: "+ deployDeptName);
		var deployEmpName = $("#deployEmpNo option:selected").text();
		$("#deployDeptName")[0].value=deployDeptName;
		$("#deployEmpName")[0].value=deployEmpName;
		var reason = $("#reason")[0].value;
		if(reason==null || reason==""){
			alert("请填写原因!");
			return;
		}
		var deployDeptId = $("#deployDeptId")[0].value;
		if(deployDeptId==null || deployDeptId==""){
			alert("请选择部门!");
			return;
		}
		 $.ajax({
             type: "POST",
             url:getContextPathTemp()+"/ruleSet/customDeploy/checkIsCanDeploy",
             data:"deployDeptId="+deployDeptId,
             async: false,
             success: function(data){
            	 var result = eval(data);
            	 if(result){
            			//$("#deployForm").attr("action", "../../ruleSet/customDeploy/bathCustomDeploy");
            			//$("#deployForm").submit(); 
            			
               			var url = getContextPathTemp()+"/ruleSet/customDeploy/bathCustomDeploy";
               			 $.ajax({
               		         type: "POST",
               		         dataType:"json",
               		         url:url,
               		         data:$("#deployForm").serialize(),
               		         async: false,
               		         success: function(data){
               		        	 if(data=="1"){
               		        		 alert("调配申请成功!"); 
               		        		return;
               		        	 }else if(data=="0"){
               		        		 alert("调配记录中,存在已被其他人调配过的记录,请重新选择!"); 
               		        		return;
               		        	 }else if(data=="4"){
               		        		 alert("用户【"+deployEmpName+"】不能接收人工调配,请重新选择!"); 
               		        		return;
               		        	 }
               		        	 else if(data=="3"){
              		        		 alert("调配异常!"); 
              		        		return;
              		        	 }
               		        	 $("#redirectForm").submit(); 
               		         }
               		     }); 	
            	 }else{
            		alert("此部门已没有该用户使用的产品，请选择其他部门!"); 
            	 }
             }
         });
	});
	
	$("#bathDeployBtnCancel").click(function(){
		
		$("#deployBtn").css("display","block");
		$("#deployBtnCancel").css("display","block");
		$("#bathDeployBtn").css("display","none");
		$("#bathDeployBtnCancel").css("display","none");
		
		$("#cusId")[0].value="";
		$("#deployCName")[0].value="";
		$("#deployMail")[0].value="";
		$("#deployPhone")[0].value="";
		$("#deployCurrentDeptNo")[0].value="";
		$("#deployCurrentEmpNo")[0].value="";
		$("#deployCurrentDeptName")[0].value="";
		$("#deployCurrentEmpName")[0].value="";
		$("#deployDeptName")[0].value="";
		$("#deployEmpName")[0].value="";
		$("#deployCurrentDeptNameLabel").html();
		$("#deployCurrentEmpNameLabel").html();
		$("#reason")[0].value="";
		$("#deployEmpNo").empty();
		$("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
		$("#deployDeptId")[0].value="";
	});
	
	initTree();
	//初始化所属部门树
	var setting = {	
			view: {selectedMulti:false},data: {keep: {parent:true,leaf:true},simpleData: {enable: true}},
			callback: {beforeDrag: beforeDrag}
	};
	function beforeDrag(treeId, treeNodes){
		return false;
	}
	$.fn.zTree.init($("#treeDemo1"), setting, zNodes);
	
	$("#deptTreeBtnCancel").click(function(){
	 	$("#deptTreeBackGround").css("display","none");
	 	$("#deptTree").css("display","none");
	});
	$("#deptTreeBtnConfirm").click(function(){
		var selectedNodeId="";
		var selectedNodeName="";
        var treeObj=$.fn.zTree.getZTreeObj("treeDemo1");
        nodes=treeObj.getSelectedNodes();
		 for ( var int = 0; int < nodes.length; int++){
			 var node = nodes[int];
			 selectedNodeId = node.id;
			 selectedNodeName = node.name;
			 break;
		} 
        if(selectedNodeId==""){
        	alert("请选择部门!");
        	return;
        }
		$("#deployDeptId").val(selectedNodeId);
		$("#tempDeptId").val(selectedNodeName);
		$("#deployDeptName").val(selectedNodeName);
		
		var deployCurrentEmpNo =  $("#deployCurrentEmpNo").val();
		//alert("deployCurrentEmpNo:"+deployCurrentEmpNo);
		if(selectedNodeId!=null && selectedNodeId!=""){
			 $.ajax({
	             type: "POST",
	             url:getContextPathTemp()+"/ruleSet/customDeploy/getEmpByDeptId",
	             data:"deptId="+selectedNodeId+"&currentEmpId="+deployCurrentEmpNo,
	             async: false,
	             success: function(data){
	             	$("#deployEmpNo").empty();
	            	$("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
	            	 if(data!=""){
	                 	var empList = eval(data);
	                	if(empList!=""){
	                    	for( var int = 0; int < empList.length; int++){
	                    		var emp = empList[int];
	                    		var empno = emp.empno;
	                    		var ename = emp.ename;
	                    		$("#deployEmpNo").append("<option value='"+empno+"'>"+ename+"</option>");
	        				}
	                	}
	            	 }
	             }
	         }); 
		}
	 	$("#deptTreeBackGround").css("display","none");
	 	$("#deptTree").css("display","none");
	});
	
	
	
	
	$("#queryDeptTreeBtnConfirm").click(function(){
		var selectedNodeId="";
		var selectedNodeName="";
        var treeObj=$.fn.zTree.getZTreeObj("treeDemo1");
        nodes=treeObj.getSelectedNodes();
		 for ( var int = 0; int < nodes.length; int++){
			 var node = nodes[int];
			 selectedNodeId = node.id;
			 selectedNodeName = node.name;
			 break;
		} 
        if(selectedNodeId==""){
        	alert("请选择部门!");
        	return;
        }
		$("#queryDeptId").val(selectedNodeId);
		$("#queryTempDeptId").val(selectedNodeName);
		if(selectedNodeId!=null && selectedNodeId!=""){
			 $.ajax({
	             type: "POST",
	             url:getContextPathTemp()+"/ruleSet/customDeploy/getEmpAndAreaByDeptId",
	             data:"deptId="+selectedNodeId,
	             async: false,
	             success: function(data){
	             	$("#queryEmpName").empty();
	            	$("#queryEmpName").append("<option value='' selected='selected'>---请选择---</option>");
	            	 if(data!=""){
	                 	var result = eval(data);
	                 	var areaList = result[0].areaList;
	                 	var empList = result[0].empList;
	                	if(empList!=""){
	                    	for( var int = 0; int < empList.length; int++){
	                    		var emp = empList[int];
	                    		var empno = emp.empno;
	                    		var ename = emp.ename;
	                    		$("#queryEmpName").append("<option value='"+ename+"'>"+ename+"</option>");
	        				}
	                	}
	                	if(areaList!=""){
	                    	for( var int = 0; int < areaList.length; int++){
	                    		var area = areaList[int];
	                    		var areaID = area.areaID;
	                    		var name =  area.name;
	                    		$("#queryArea").append("<option value='"+name+"'>"+name+"</option>");
	        				}
	                	}
	            	 }
	             }
	         }); 
		}
	 	$("#deptTreeBackGround").css("display","none");
	 	$("#deptTree").css("display","none");
	});
	
	
	//清空			 		 
	$("#clean").click(function(){
		$("#customerId")[0].value="";
		$("#contact")[0].value="";
		$("#phone")[0].value="";
		$("#email").val("");
		$("#queryDeptId").val("");
		$("#queryTempDeptId").val("");
		$("#queryEmpName").val("");
		$("#queryArea").val("");
	});
	
	query();
});

function query(pageNow) {
	controllerWaitingBar(true);
	//获取项目上下文路径
	rootPath = $('#rootPath').val();
	//获取要查询的客户类型
	var customerType=$("#customerType").val();
	
	//获取当前页的下一页/上一页
	if(!pageNow) {
		pageNow = 1;
	}else if(pageNow == "nextPage") {
		pageNow = $('#pageNow').val();
		var pageCount = $('#pageCount').html();
		//如果当前页是最后一页 则下一页无效
		if(pageNow == pageCount) {
			controllerWaitingBar(false);
			return ;
		}
		pageNow = $('#pageNow').val()*1 + 1;
	}else if(pageNow == "prevPage") {
		pageNow = $('#pageNow').val();
		//如果当前页是第一页 则上一页无效
		if(pageNow == "1") {
			controllerWaitingBar(false);
			return ;
		}
		pageNow = $('#pageNow').val()*1 - 1;
	}else if(pageNow == "lastPage") {
		pageNow = $('#pageCount').html();
	}
	
	
	var customId = null;
	var customIdForNull = $('#customIdForNull').val();
	if(customIdForNull=="--"){
		customId = "--";
		$('#customIdForNull').val("");
	} else {
		customId =  $('#customId').val();
		
	}
	var customName = $('#customName').val();
	var phone = $('#phone').val();
	var email = $('#email').val();
	var empId = $('#emp').val();
	var deptId = $('#deptId').val();
	var regionalId = $('#area').val();
	var startAddTime = $('#startTime').val();
	var endAddTime = $('#endTime').val();
	var startDueTime = $('#startDueTime').val();
	var endDueTime = $('#endDueTime').val();
	var startDeployTime = $('#startDeployTime').val();
	var endDeployTime = $('#endDeployTime').val();
	var isSort = $('#isSort').val();
	var isBuy = $('#isBuy').val();
	var productCode = $('#productCode').val();

	var nolinkedDay1 = $('#nolinkedDay1').val();
	var nolinkedDay2 = $('#nolinkedDay2').val();
	if(productCode!=null&& productCode!=""){
		if(startDueTime==null || startDueTime=="" ||endDueTime==null||endDueTime=="") {
			alert("商品和到期日期条件必须同时存在！");
			controllerWaitingBar(false);
			return;
		}
	}
	if(startDueTime!=null && startDueTime!="" &&endDueTime!=null&&endDueTime!="") {
		if(productCode==null || productCode==""){
			alert("商品和到期日期条件必须同时存在！");
			controllerWaitingBar(false);
			return;
		}
	}
	if(!checkForm()) {
		return ;
	}
	
	var url = rootPath + "/customerManage/queryCustomer";
	$.post(
		url,
		{
			"customId": customId,
			"customName": customName,
			"phone": phone,
			"email": email,
			"empId": empId,
			"isBuy": isBuy,
			"deptId": deptId,
			"regionalId": regionalId,
			"startAddTime": startAddTime,
			"startDeployTime":startDeployTime,
			"endDeployTime":endDeployTime,
			"endAddTime": endAddTime,
			"startDueTime": startDueTime,
			"endDueTime": endDueTime,
			"customerType": customerType,
			"productCode": productCode,
			"nolinkedDay1": nolinkedDay1,
			"nolinkedDay2": nolinkedDay2,
			"isSort": isSort,
			"pageNow": pageNow
		},
		function(data) {
			var json = eval(data);
			if(5 == json) {
				location.href = rootPath + "/login/loginPage";
				return ;
			}
			var html = "";
			html += '<tr>';
			html += '<th>选择&nbsp;<input type="checkbox" onclick="selectedBox(this)" /></th>';
	        html += '<th>会员编号</th>';
	        html += '<th>客户名称</th>';
	        html += '<th>所属人</th>';
	        html += '<th>所属分公司</th>';
	        html += '<th>所属区域</th>';    
	        html += '<th>注册日期</th>';    
	        html += '<th>未联系天数</th>';  
	        html += '<th>注册来源</th>';
	        html += '<th>是否购买过商品</th>';
	        html += '<th>操作</th>';    
	        html += '</tr>'; 
	        var isHasCustomAlot =  $('#isHasCustomAlot').val();
	        var isResponsible = $('#isResponsible').val();
	        var userId = $('#userId').val();
	        var currentdid = $('#currentdid').val();
	        if(json.length == 0) {
				html += '<tr><td colspan="12">没有查到相关数据！</td></tr>';
			}else { 
				for(var i=0; i<json.length; i++) {
					html += '<tr>';
					var checkbox = "";
					if(isResponsible!=0 && ((json[i].approveStatus!=null && json[i].approveStatus==3) || (json[i].approveStatus!=null && json[i].approveStatus==1 || json[i].approveStatus==0) || (json[i].approveStatus == null)) ){
					
						checkbox ='<td><input id="multiChoice_'+json[i].ecrId+'" type="checkbox" value="'+
						json[i].customId +':'+
						json[i].pushHistoryId +':'+
						json[i].pushHistoryProductId + ':'+
						json[i].pusherId +
						'"  /></td>';
					} else {
						
						if(userId == json[i].empId && customState == 0) {
							checkbox ='<td><input type="checkbox" value="'+
							json[i].ecrId +':'+
							json[i].customId +':'+
							json[i].empId +':'+
							json[i].productId +':'+
							'"  /></td>';
						}else {
							checkbox="<td></td>";
						}
						
					}
					
					html += checkbox;
					html += '<td><a href="#" onclick="goCustomerDetails(' + "'" + json[i].customId + "'" + ')">' + json[i].customId + '</a></td>';
					html += '<td>' + json[i].organizeNameCN + '</td>';
					html += '<td>' + json[i].empName + '</td>';
					if(json[i].companyAbb!=null){
						html += '<td>' + json[i].companyAbb + '</td>';
					}else{
						html += '<td>' + '</td>';
					}
					html += '<td>' + json[i].areaName + '</td>';
					html += '<td>' + json[i].addTime + '</td>';
					html += '<td>' + json[i].nolinkedDay + '</td>';
					html += '<td>' + json[i].customerSource + '</td>';
					if(json[i].isBuy == 1)
						isBuy="是";
					else
						isBuy="否";
					html += '<td>' + isBuy + '</td>';
					html += '<td>';
					if(json[i].approveStatus!=null &&json[i].approveStatus==2 ){
						
						if(isHasCustomAlot==0){
							html += "【调配审批中】";
						} 
						
					} else if (json[i].approveStatus!=null && json[i].approveStatus==3){
						
						if(isHasCustomAlot==0){
							html+='<a id="'+json[i].cusId+'stateLabel" href=javaScript:customDeploy("'+json[i].ecrId+'","'+json[i].cmaId+'","'+json[i].customId+'","'+json[i].deptno+'","'+json[i].dname+'","'+json[i].empId+'","'+json[i].ename+'","'+json[i].customName+'","'+json[i].phone+'","'+json[i].email+'","'+json[i].productId+'","'+json[i].productCode+'")>调配</a>【审批超时】'
						}
					} else if(json[i].approveStatus!=null && (json[i].approveStatus==1||json[i].approveStatus==0)) {
						
						if(isHasCustomAlot==0){
							html+='<a id="'+json[i].cusId+'stateLabel" href=javaScript:customDeploy("'+json[i].ecrId+'","'+json[i].cmaId+'","'+json[i].customId+'","'+json[i].deptno+'","'+json[i].dname+'","'+json[i].empId+'","'+json[i].ename+'","'+json[i].customName+'","'+json[i].phone+'","'+json[i].email+'","'+json[i].productId+'","'+json[i].productCode+'")>调配</a>'
						}
						
					} else if(json[i].approveStatus == null) {
						
						if(isHasCustomAlot==0){
							html+='<a id="'+json[i].cusId+'stateLabel" href=javaScript:customDeploy("'+json[i].ecrId+'","'+json[i].cmaId+'","'+json[i].customId+'","'+json[i].deptno+'","'+json[i].dname+'","'+json[i].empId+'","'+json[i].ename+'","'+json[i].customName+'","'+json[i].phone+'","'+json[i].email+'","'+json[i].productId+'","'+json[i].productCode+'")>调配</a>'
						}
					}
					
					html += '</td>'; 
					html += '</tr>';
				}
			}
			
			$('#dataList').html(html);
			
			//显示分页
			if(json.length) {
				var pageNow = json[0].pageNow;
				var pageSize = json[0].pageSize;
				var rowCount = json[0].rowCount;
				var pageCount = json[0].pageCount;
				
				$('#pageNow').val(pageNow);
				$('#pageSize').html("1-" + pageSize);
				$('#rowCount').html(rowCount);
				$('#pageIndex').html(pageNow);
				$('#pageCount').html(pageCount);
			}else {
				$('#pageNow').val("1");
				$('#pageSize').html("1-50");
				$('#rowCount').html("0");
				$('#pageIndex').html("1");
				$('#pageCount').html("1");
			}
			controllerWaitingBar(false);
		}
	);
}

function customDeploy(ecrId,cmaId,cusId,deptno,dname,empno,ename,cname,phone,email,productId,productCode){
	//alert("ecrId: "+ ecrId);
	//alert("cmaId: "+ cmaId);
	 $("#ecrId")[0].value=ecrId;
	 $("#cmaId")[0].value=cmaId;
	 $("#cusId")[0].value=cusId;
	 $("#deployCName")[0].value=cname;
	 $("#deployMail")[0].value=email;
	 $("#deployPhone")[0].value=phone;
	 $("#deployCurrentDeptNo")[0].value=deptno;
	 $("#deployCurrentEmpNo")[0].value=empno;
	 $("#deployCurrentDeptName")[0].value=dname;
	 $("#deployCurrentEmpName")[0].value=ename;
	 $("#productId")[0].value=productId;
	 $("#productCodeDeploy")[0].value=productCode;
	 $("#deployDeptName")[0].value=$("#deployDeptId").text();
	 $("#deployEmpName")[0].value=$("#deployEmpNo").text();
	 $("#deployCurrentDeptNameLabel").html(dname);
	 $("#deployCurrentEmpNameLabel").html(ename);
	 
   	 $("#greyBackGround").css("display","block");
	 $("#deploy").fadeIn("slow"); 
}

function bathCustomDeploy(){
	var ecrIdStr="";
	var list = $("input[id^=multiChoice_][type='checkbox']:checked");
	if(list.length>0){
		for(var int = 0; int < list.length; int++){
			var id = list[int].id.replace("multiChoice_","");
			if(ecrIdStr==""){
				ecrIdStr=id;
			}else{
				ecrIdStr = ecrIdStr+","+id;
			}	
		}
	}
	if(ecrIdStr==""){
		alert("请选择记录!");
		return;
	}
	
	$("#ecrIdStr").val(ecrIdStr);
	$("#deployBtn").css("display","none");
	$("#bathDeployBtn").css("display","block");

	$("#deployCName")[0].value="";
	$("#deployMail")[0].value="";
	$("#deployPhone")[0].value="";
	$("#deployCurrentDeptNo")[0].value="";
	$("#deployCurrentEmpNo")[0].value="";
	$("#deployCurrentDeptName")[0].value="";
	$("#deployCurrentEmpName")[0].value="";
	$("#deployDeptName")[0].value="";
	$("#deployEmpName")[0].value="";
	$("#deployCurrentDeptNameLabel").html();
	$("#deployCurrentEmpNameLabel").html();
	$("#reason")[0].value="";
	$("#deployEmpNo").empty();
	$("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
	$("#deployDeptId")[0].value="";

	$("#greyBackGround").css("display","block");
	$("#deploy").fadeIn("slow");
}


function bathAllCustomDeploy(){
	if(!confirm("确定要对全部结果集进行调配？")){
		return;
	}
	
	var customerType=$("#customerType").val();
	var customId = $('#customId').val();
	var customName = $('#customName').val();
	var phone = $('#phone').val();
	var email = $('#email').val();
	var empId = $('#emp').val();
	var deptId = $('#deptId').val();
	var regionalId = $('#area').val();
	var startAddTime = $('#startTime').val();
	var endAddTime = $('#endTime').val();
	var startDeployTime = $('#startDeployTime').val();
	var endDeployTime = $('#endDeployTime').val();
	var isSort = $('#isSort').val();
	var isBuy = $('#isBuy').val();
	if(!checkForm()) {
		return ;
	}
	var url = rootPath + "/customerManage/queryCustomer";
	$.post(
		url,
		{
			"customId": customId,
			"customName": customName,
			"phone": phone,
			"email": email,
			"empId": empId,
			"isBuy": isBuy,
			"deptId": deptId,
			"regionalId": regionalId,
			"startAddTime": startAddTime,
			"startDeployTime":startDeployTime,
			"endDeployTime":endDeployTime,
			"endAddTime": endAddTime,
			"customerType": customerType,
			"isSort": isSort,
			"pageNow": "1",
			"pageSize":"100000"
		},
		function(data) {
			var json = eval(data);
			if(5 == json) {
				location.href = rootPath + "/login/loginPage";
				return ;
			}
			var ecrIdStr="";
			for(var i=0; i<json.length; i++) {
				var customState = json[i].customState;
				var approveStatus = json[i].approveStatus;
				if(approveStatus!=2){
					
					if(ecrIdStr==""){
						ecrIdStr=json[i].ecrId;
					}else{
						ecrIdStr = ecrIdStr+","+json[i].ecrId;
					}	
					
				} /*else if(customState!=0 && approveStatus==null) {
					if(ecrIdStr==""){
						ecrIdStr=json[i].ecrId;
					}else{
						ecrIdStr = ecrIdStr+","+json[i].ecrId;
					}	
				}*/
			}
			if(ecrIdStr==""){
				alert("没有需要调配的会员");
				return;
			}
			$("#ecrIdStr").val(ecrIdStr);
			$("#deployBtn").css("display","none");
			$("#bathDeployBtn").css("display","block");

			$("#deployCName")[0].value="";
			$("#deployMail")[0].value="";
			$("#deployPhone")[0].value="";
			$("#deployCurrentDeptNo")[0].value="";
			$("#deployCurrentEmpNo")[0].value="";
			$("#deployCurrentDeptName")[0].value="";
			$("#deployCurrentEmpName")[0].value="";
			$("#deployDeptName")[0].value="";
			$("#deployEmpName")[0].value="";
			$("#deployCurrentDeptNameLabel").html();
			$("#deployCurrentEmpNameLabel").html();
			$("#reason")[0].value="";
			$("#deployEmpNo").empty();
			$("#deployEmpNo").append("<option value='' selected='selected'>---请选择---</option>");
			$("#deployDeptId")[0].value="";

			$("#greyBackGround").css("display","block");
			$("#deploy").fadeIn("slow");
		});
}

function displayDeptTree(){
 	 $("#deptTreeBackGround").css("display","block");
 	 $("#queryDeptTreeBtnConfirm").css("display","none");
 	 $("#deptTreeBtnConfirm").css("display","block");
	 $("#deptTree").fadeIn("slow"); 
}
function queryDeptTree(){
	 $("#deptTreeBtnConfirm").css("display","none");
	 $("#queryDeptTreeBtnConfirm").css("display","block");
	 $("#deptTreeBackGround").css("display","block");
	 $("#deptTree").fadeIn("slow"); 
}

function selectAll(){
	if($("#selectAll").attr("checked")==true){
		$('input[id^=multiChoice_]').attr("checked",true); 
	}else{
		$('input[id^=multiChoice_]').attr("checked",false); 
		
	}
}


function getContextPathTemp() {
	var result=$("#rootPath").val();
    return result;
}